using UnityEngine;
using System.Collections;

public class HUDHolder : MonoBehaviour
{
	public HUDType hudType;
	
	protected HUD hud;
	Camera worldCam = null;
	Camera nguiCam = null; 
	
	void Start()
	{
		worldCam = Camera.main;
		nguiCam = UICamera.mainCamera;
		
		// initialize things
		if(BattleUI.instance != null)
		{
			hud = BattleUI.instance.CreateHUD(hudType, transform.parent.gameObject);
			UpdateHud();
		}
	}
	
	void OnDestroy()
	{
		if(BattleUI.instance != null)
		{
			if(hud != null)
				BattleUI.instance.RemoveHUD(hud);
		}
	}
	
	void Update()
	{
		UpdateHud();
	}
	
	void UpdateHud()
	{
		if(hud != null)
		{
			Vector3 UIPosition = nguiCam.ScreenToWorldPoint (worldCam.WorldToScreenPoint (transform.position));
			UIPosition.z = 0;
			hud.transform.position = UIPosition;
		}
	}
}

